export default {
  namespaced:true,
  state(){
    return {
      address:JSON.parse(uni.getStorageSync('address')  || '{}'),
      token:uni.getStorageSync('token') || '',
      userInfo:JSON.parse(uni.getStorageSync('userInfo')  || '{}'),
      redirectInfo:null
    }
  },
  mutations:{
    //更新地址
    addAddress(state,add){
      state.address = add
      this.commit('m_address/saveAddressToLocal')
    },
    //地址持久化
    saveAddressToLocal(state){
      uni.setStorageSync('address',JSON.stringify(state.address))
    },
    //更新用户信息
    updateUserInfo(state,user){
      state.userInfo = user
      this.commit('m_address/saveUserInfoToLocal')
    },
    //用户信息持久化
    saveUserInfoToLocal(state){
        uni.setStorageSync('userInfo',JSON.stringify(state.userInfo))
    },
    //保存token
    saveToken(state,token){
      state.token = token
      this.commit('m_address/saveTokenToLocal')
    },
    //token持久化
    saveTokenToLocal(state){
       uni.setStorageSync('token',state.token)
    },
    //更新重定向对象
    updateRedirectInfo(state,obj){
      state.redirectInfo = obj
    }
  },
  getters:{
    addStr(state){
      if(!state.address.provinceName) return ''
      return state.address.provinceName + state.address.cityName + state.address.countyName + state.address.detailInfo
    }
  }
}